<?php 
class IndexController extends Controller{
	public function __init(){
		if(is_file(MODULE_PATH.'lock.php')){
			$this->display('lock');
		}

	}

	public function install(){
		$this->display();
	}

	public function setDb(){
		$this->display();
	}

	public function insertSql(){
		if(!@mysql_connect($_POST['DB_HOST'],$_POST['DB_USER'],$_POST['DB_PASSWORD'])){
			$this->error('主机连接失败','setDb');
		}
		if(!mysql_select_db($_POST['DB_DATABASE'])){
			$this->error('数据库连接失败','setDb');
		}
		//更新C(函数)记录的网站配置
		C($_POST);
		$db=M();
		$db_prefix='hd_';
		//执行创建表结构的sql文件
		require MODULE_PATH.'Sql/structure.php';
		$files=Dir::tree(MODULE_PATH.'Sql');
		// p($files);exit;
		foreach ($files as $f) {
			if(substr($f['filename'],0,3)=='hd_'){
				require $f['path'];
			}
		}

		//更新管理员的帐号信息
		$code=mt_rand(1,1000).time();
		$data['uid']=1;
		$data['username']=$_POST['username'];
		$data['code']=$code;
		$data['password']=md5($_POST['password'].$code);
		$db->table('admin')->save($data);
		//更新配置文件
		$data="<?php \nreturn ".var_export($_POST,true).";\n?>";
		file_put_contents(APP_CONFIG_PATH.'db.inc.php', $data);
		go('finish');


	}

	public function finish(){
		$this->display();
		touch(MODULE_PATH.'lock.php');
	}

}

?>